package org.example.springcloud.controller;

import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.EurekaClient;
import org.example.springcloud.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    EurekaClient client;

    @GetMapping("/user/{id}")
    User getUser(@PathVariable long id) {

        return new User(id);
    }

    @GetMapping("/eurekaInfo")
    String info() {
        InstanceInfo instanceInfo = client.getNextServerFromEureka("PROVIDER-USER", false);
        return instanceInfo.getHomePageUrl();
    }
}
